/**
 * 项目名称: Topic_35.cpp
 * 项目路径: study/DataStructure/LeetCode/二分
 * 编辑时间: 2024年09月07日15时11分38秒
 * 用   户: 轻尘
 */

#include <bits/stdc++.h>

using namespace std;

class Solution {
public:
    int find(int nums[],int x,int len){
        int l = 0,r= len-1;
        while (l<r){
            int mid = (l+r+1)/2;
            cout<<l<<" "<<r<<" "<<mid<<endl;
            if(nums[mid]>x)r=mid-1;
            else l=mid;
        }
        return l;
    }
    int searchInsert(vector<int>& nums, int target) {
        int p[nums.size()];
        int cnt = 0;
        int* op = p;
        for(auto x:nums)*(op+cnt)=x,cnt++;
        int index = find(p,target,nums.size());
        if(p[index]<target)return index+1;
        else if(p[index]==target)return index;
        else return max(0,index-1);
    }
};
